import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/common/system_address_item.dart';
import 'package:xinxuan/controllers/my_controller/address_controller/address_controller.dart';
import 'package:xinxuan/controllers/my_controller/address_controller/address_province_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:get/get.dart';
import 'package:xinxuan/utils/color_util.dart';

class AddressProvince extends StatelessWidget {

  final AddressController addressController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarUtil(
        title: '选择省份',
        backgroundColor: pageBgColor,
      ),
      body: GetBuilder<AddressProvinceController>(
        init: AddressProvinceController(),
        builder: (controller) {
          return ScrollConfigurationCommon(child: ListView(
            children: controller.providerArr.map((item) {
              return SystemAddressItem(title: '${item.title}', isSelected: addressController.providerItem.value.id == item.id, onTap: () {
                addressController.changeProviderAddress(item);
                Get.offNamed(
                  '${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ADDRESS_LIST_PAGE}${AppRouters.ADD_EDIT_ADDRESS_PAGE}${AppRouters.ADDRESS_CITY}',
                  arguments: {
                    'id': item.id
                  }
                );
              });
            }).toList(),
          ));
        },
      ),
    );
  }
}